$(function () {
    $("#login-btn").click(function () {
        var emailStr = document.getElementById("username").value;
        var passwordStr = document.getElementById("password").value;

        console.log(emailStr);
        console.log(passwordStr);

        if (!emailStr) {
            alert("请填写正确的邮箱地址！")
            return;
        }
        var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
        if(reg1.test(emailStr) == false) {
            alert('邮箱格式不正确');
            return false;
        }
        if (!passwordStr) {
            alert("请输入密码！")
            return;
        }

        console.log("cookie:"+document.cookie);
        var urlstr = "/api/user/login/" + emailStr + "/" + passwordStr;
        $.ajax({
            type: "post",
            url: urlstr,
            data: {
                email: emailStr,
                password: passwordStr
            },
            success: function (data) {
                //   alert(data);
                if(data.code == 200){
                    location.href = "index.html";
                }else{
                    document.getElementById("msg").innerText = data.msg;
                }
            }
        });
    });
});